/*
 * 作者：姚俊
 * 功能：方向学生的学位论文的action
 * 日期：2015-07-01
 */
package leader.action;

import java.util.*;

import com.opensymphony.xwork2.ActionContext;

import admin.action.fruits.Constant;
import admin.service.fruits.DegreePaperService;
import admin.service.member.StudentService;
import admin.service.member.TeacherService;

import teacher.bean.Studegreepaper;
import teacher.bean.Students;
import teacher.bean.Teacher;

public class DirectStudentPaperAction {
	
	private List<Studegreepaper> stuPapers;
	private List<Students> students=new ArrayList<Students>();
	private List<Teacher> teachers=new ArrayList<Teacher>();
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;
	private int flag;

	public List<Studegreepaper> getStuPapers() {
		return stuPapers;
	}

	public void setStuPapers(List<Studegreepaper> stuPapers) {
		this.stuPapers = stuPapers;
	}
	

	public List<Students> getStudents() {
		return students;
	}

	public void setStudents(List<Students> students) {
		this.students = students;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}
	
	public List<Teacher> getTeachers() {
		return teachers;
	}

	public void setTeachers(List<Teacher> teachers) {
		this.teachers = teachers;
	}

	public String execute()
	{
		this.setFlag(1);
		Teacher leader=(Teacher)ActionContext.getContext().getSession().get("leader");
		
		//当前页为零的时候，把当前页变成1
		if(this.getCurrentPage()==0)
			this.setCurrentPage(1);
		
		int add=0;
		//最后一页
		if(new DegreePaperService().getCountDirectionDegreePaperByAll(null,leader)%Constant.pageSize!=0)
		{
			add=1;
		}
		
		this.setEndPage(new DegreePaperService().getCountDirectionDegreePaperByAll(null,leader)/Constant.pageSize+add);
		this.setCounts(new DegreePaperService().getCountDirectionDegreePaperByAll(null,leader));
		
		this.setStuPapers(new DegreePaperService().getSegregateDirectionDegreePaperByAll(null,
				leader,(this.getCurrentPage()-1)*Constant.pageSize+1,Constant.pageSize));
		
		for(Studegreepaper paper:this.getStuPapers())
		{
			Students stu=new StudentService().getStudentById(paper.getStuId());
			this.getStudents().add(stu);
			Teacher t=new Teacher();
			t.setTeaId(stu.getTeaId());
			this.getTeachers().add(new TeacherService().getTeacher(t));
		}
		return "succ";
	}
}
